#include "scheduler.h"
#include "led.h"
#include "lcd.h"
#include "key.h"
#include "sram.h"
#include "malloc.h"

//****************************
//****************************
void LED_Task(void)
{
	LED_Show();
}

//****************************
//****************************
void KEY_Task(void)
{
	KEY_Scan();
}

//****************************
//****************************
void LCD_Task(void)
{
	static uint8_t *p=0,*tp=0,paddr[18],sramx=0,i=0;
	
	switch(keyflag.all)
	{
		case 0x02:p=MyMalloc(sramx,2048);
							if(p!=NULL)sprintf((char*)p,"Memory Malloc Test%03d",i);
							break;
		case 0x04:if(p!=NULL)
							{
								sprintf((char*)p,"Memory Malloc Test%03d",i);
								LCD_ShowString(30,250,200,16,16,(char *)p);
							}
							break;
		case 0x08:MyFree(sramx,p);p=0;break;
		case 0x01:sramx=!sramx;
							if(sramx)
								LCD_ShowString(30,170,200,16,16,"SRAMEX");
							else
								LCD_ShowString(30,170,200,16,16,"SRAMIN");
							break;
							
	}
	if(tp!=p)
	{
		tp=p;
		sprintf((char*)paddr,"P Addr:0X%08X",(uint32_t)tp);
		LCD_ShowString(30,230,200,16,16,(char *)paddr);
		if(p)
			LCD_ShowString(30,250,200,16,16,(char *)p);
		else
			LCD_Fill(30,250,239,266,WHITE);
	}
	LCD_ShowNum(30+96,190,MyMemPerused(SRAMIN),3,16);
	LCD_ShowNum(30+96,210,MyMemPerused(SRAMEX),3,16);
}
